

import 'dart:convert';

import 'package:flutter_book/api/api.dart';
import 'package:flutter_book/data/model/yck/yck_rule_book_2_model.dart';
import 'package:flutter_book/data/model/yck/yck_rule_book_3_model.dart';
import 'package:flutter_book/util/extensions/string_extensions.dart';

class YckMumuceoComApi{
  static String httpUrl="yck.mumuceo.com";


  //获取yck的资源规则
  static Future<List<YckRuleBook3Model>?> getYckRuleList(String url) async {
    if (!(url.contains(httpUrl))) {
      "获取yck的资源规则：失败-不是url".print;
      return null;
    }
    List<YckRuleBook3Model> videoList = <YckRuleBook3Model>[];
    Map<String, dynamic> params = {};
    String? data = await requestApi(url, params);
    if (data == null) {
      "获取资源失败".print;
      return null;
    }
    List responseJson = json.decode(data);
    videoList = responseJson.map((m) {
      // try {
        //todo 有问题
        // throw new Exception();
        // if (m["ruleSearch"] != null && m["ruleSearch"].toString().contains("=searchKey") ||
        //     m["ruleSearchUrl"] != null && m["ruleSearchUrl"].toString().contains("=searchKey")) {
        //   return YckRuleBook2Model.fromJson(m).convertNew();
        // }
        return YckRuleBook3Model.fromJson(m);
      // } catch (e) {
      //   "获取yck的资源规则：解析失败：${e.toString()}".print;
      //   "${m["bookSourceName"]}".print;
      //   return YckRuleBook2Model.nullModel().convertNew();
      // }
    }).toList();
    return videoList;
  }
}